package com.zmm.book.keep.config;

import com.zmm.book.keep.interceptor.BookKeepAuthInterceptor;
import com.zmm.util.auth.filter.AnonymousFilter;
import com.zmm.util.auth.registry.ReqParamResolverComposite;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 900045
 * @description:
 * @name BookKeepAppInterceptorConfig
 * @date By 2021-09-28 10:25:12
 */
@Configuration
public class BookKeepAppInterceptorConfig implements WebMvcConfigurer {

	@Resource
	private BookKeepAuthInterceptor bookKeepAuthInterceptor;


	@Override
	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
		WebMvcConfigurer.super.addArgumentResolvers(resolvers);
		resolvers.add(new ReqParamResolverComposite());
	}

	/**
	 * 增加拦截器
	 * @author: 900045
	 * @date: 2021-04-07 15:21:11
	 * @throws
	 * @param registry: 
	 * @return: void
	 **/
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		//指定拦截器类//指定该类拦截的url
		bookKeepAuthInterceptor.addPreFilter(new AnonymousFilter());
		registry.addInterceptor(bookKeepAuthInterceptor)
				.addPathPatterns("/**").excludePathPatterns("/static/**");
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// addResourceHandler 请求路径
		// addResourceLocations 在项目中的资源路径
		// setCacheControl 设置静态资源缓存时间
		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
				//.setCacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic())
		//registry.addResourceHandler("/plugins/**").addResourceLocations("classpath:/resources/plugins/")
		WebMvcConfigurer.super.addResourceHandlers(registry);
	}
}
